package www.admin.service.impl;

import www.admin.model.Operation;

import javax.annotation.Resource;

import www.admin.dao.IOperationDao;

import org.springframework.stereotype.Service;

import www.admin.mybatis.Criteria;
import www.admin.service.IOperationService;
import www.admin.utils.Layui;
import www.admin.utils.MessageConstant;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * 
 * Operation
 * 
 **/

@Service
public class OperationServiceImpl implements IOperationService{


	public Layui queryPage (Criteria<Operation> param){
		PageHelper.startPage(param.getStartIndex(), param.getPageSize());
		List<Operation> list = operationRepository.queryPage(param);
			PageInfo<Operation> paInfo = new PageInfo<Operation>(list);
	return Layui.data((int)paInfo.getTotal(), paInfo.getList()); }

	public Integer queryPageCount (Criteria<Operation> param){
		return (Integer) operationRepository.queryPageCount(param);
	}

	public Operation  queryEntity (String id ){
		return operationRepository.queryEntity(id);
	}

	public String deleteById (String id ){
		int result = operationRepository.deleteById(id);
			if ( result != 1) {
					return MessageConstant.USER_TYPE_3;
			}
			return null;
	}

	public String insert(Operation record ){
		int result = operationRepository.insert(record);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_4;
			}
			return null;
	}

	public String update (Criteria<Operation> param){
		int result = operationRepository.update(param);
			if ( result != 1) { 
					return MessageConstant.USER_TYPE_5;
			}
			return null;
	}
	
	@Override
	public String deleteAll(String[] id) {
		int result = operationRepository.deleteAll(id);
		if ( result != 1) { 
			return MessageConstant.USER_TYPE_3;
	    }
	    return null;
	}

	@Resource
	private IOperationDao operationRepository;

}